package agenceVoyageVirtuel.client.viewer;

import java.util.ArrayList;
import java.util.List;

import agenceVoyageVirtuel.client.beans.PackData;
import agenceVoyageVirtuel.client.beans.VoyageData;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class PackViewer extends Composite implements ClickHandler{
	private FocusPanel focusPanel;
	private final PackData pack;
	private Image image;
	private VerticalPanel verticalPanel;
	private Label lbl;

	public PackViewer(PackData pack) {
		this.pack = pack;
		focusPanel = new FocusPanel();
		initWidget(focusPanel);
		verticalPanel = new VerticalPanel();
		focusPanel.add(verticalPanel);
		
		lbl = new Label("Pack : "+pack.getLibPack());
		verticalPanel.add(lbl);

		final List<Image> images = new ArrayList<Image>();
		List<VoyageData> voyages = pack.getVoyages();
		for(int i = 0; i<voyages.size();i++){
			images.add(new Image("images/"+voyages.get(i).getNomImage()));
			images.get(i).setPixelSize(200, 150);
		}
		image = images.get(0);
		
//		new Animation() {
//			int i = 0;
//			@Override
//			protected void onUpdate(double progress) {
//				if(progress==1){
//					setImage(images.get(i++%images.size()));
//					run(2000);
//				}
//			}
//		}.run(2000);
		
		verticalPanel.add(image);
		image.addClickHandler(this);
		lbl.addClickHandler(this);
	}

	protected void setImage(Image image) {
		verticalPanel.clear();
		this.image = image;
		verticalPanel.add(this.image);
		verticalPanel.add(lbl);
//		focusPanel.setWidget(verticalPanel);
//		initWidget(focusPanel);
	}

	public FocusPanel getFocusPanel() {
		return focusPanel;
	}

	public PackData getPack() {
		return pack;
	}
	
	@Override
	public void onClick(ClickEvent event) {
		focusPanel.fireEvent(event);
	}
}
